package com.supermali.behavior.up_down.hinder;

import com.supermali.behavior.up_down.UpDownBehavior;
import com.supermali.entity.map.hinder.HinderMapAbstract;

public class HinderUpDown extends UpDownBehavior {

    private HinderMapAbstract hinderMapAbstract;

    private long upTime = 0;
    private long downTime = 0;

    public HinderUpDown(HinderMapAbstract hinderMapAbstract) {
        this.hinderMapAbstract = hinderMapAbstract;
    }

    @Override
    public void upDown(long delta) {

        // 上1秒
        if(upTime<100) {
            upTime += delta;
            double ds = delta * 0.1;
            hinderMapAbstract.setY(hinderMapAbstract.getY() + ds);
        }else {
            // 下1秒
            if(downTime<100) {
                downTime += delta;
                double ds = delta * 0.1;
                hinderMapAbstract.setY(hinderMapAbstract.getY() - ds);
            }else {
                upTime=0;
                downTime=0;
                setStatus(0);
                double v = Math.floor((hinderMapAbstract.getY() + (double) 16 / 2) / 16) * 16;
                hinderMapAbstract.setY(v);
            }
        }
    }
}
